I want to use inlinframe to show a popup preview print page and here is my problem:
Java:
Form form = new Form("form");
form.setOutputMarkupId(true);
form.add(new AjaxSubmitLink("test") {
#Override
protected void onSubmit(AjaxRequestTarget art, Form<?> form) {
containerPrint.add(/*another inlineframe*/)
art.addComponent(containerPrint);
}
});
add(form);
Html:
<form wicket:id="form">
<input type="button" wicket:id="test"></input>
</form>
<div wicket:id="page" style="width: 0px;height: 0px">
<iframe wicket:id="printPage" width="0px" height="0px">
</iframe>
</div>
I want to replace inlineiframe with another inlineiframe by clicking test button
but by clicking button im getting this problem
WicketMessage: org.apache.wicket.WicketRuntimeException: component form:panel:panel:panel:mcGridViewInfo:GridViewInfo:form:<b>test not found on page</b> ir.mersad.ui.authenticationAndAuthorization.Office[id = 1], listener interface = [RequestListenerInterface name=IActivePageBehaviorListener, method=public abstract void org.apache.wicket.behavior.IBehaviorListener.onRequest()]
Root cause:
org.apache.wicket.WicketRuntimeException: component form:panel:panel:panel:mcGridViewInfo:GridViewInfo:form:test not found on page ir.mersad.ui.authenticationAndAuthorization.Office[id = 1], listener interface = [RequestListenerInterface name=IActivePageBehaviorListener, method=public abstract void org.apache.wicket.behavior.IBehaviorListener.onRequest()]
at org.apache.wicket.request.AbstractRequestCycleProcessor.resolveListenerInterfaceTarget(AbstractRequestCycleProcessor.java:427)
at org.apache.wicket.request.AbstractRequestCycleProcessor.resolveRenderedPage(AbstractRequestCycleProcessor.java:472)
at org.apache.wicket.protocol.http.WebRequestCycleProcessor.resolve(WebRequestCycleProcessor.java:144)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1339)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1465)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:486)
at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:319)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Complete stack:
org.apache.wicket.protocol.http.request.InvalidUrlException: org.apache.wicket.WicketRuntimeException: component form:panel:panel:panel:mcGridViewInfo:GridViewInfo:form:test not found on page ir.mersad.ui.authenticationAndAuthorization.Office[id = 1], listener interface = [RequestListenerInterface name=IActivePageBehaviorListener, method=public abstract void org.apache.wicket.behavior.IBehaviorListener.onRequest()]
at org.apache.wicket.protocol.http.WebRequestCycleProcessor.resolve(WebRequestCycleProcessor.java:262)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1339)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1465)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:486)
I already know that the problem is with:
container.add(new InlineFrame("printPage", new EmptyPage()));
cause its work fine when i replaced it with a label but i dont know whats the problem
It's not totally clear what the problem is (some code is obviously missing). It looks like you are adding a new component instead of replacing the old one.
Try it like this:
public class HomePage extends WebPage {
private InlineFrame iframe = new InlineFrame("iframe", new OtherPage());
public HomePage() {
iframe.setOutputMarkupId(true);
Form form = new Form("form");
form.setOutputMarkupId(true);
form.add(new AjaxSubmitLink("test") {
#Override
protected void onSubmit(AjaxRequestTarget art, Form<?> form) {
InlineFrame newIframe = new InlineFrame("iframe", new OtherPage());
iframe.replaceWith(newIframe);
iframe = newIframe;
art.add(iframe);
}
});
add(form, iframe);
}
}
It's important to
call replaceWith so that Wicket can update the component tree accordingly
change your reference of iframe to point to the new component
Simply Replace previous frame
#Override
public void onClick(AjaxRequestTarget target) {
InlineFrame newIframe = new InlineFrame("iframe", PersonalInformationPage.class);
iframe.replaceWith(newIframe);
iframe = newIframe;
target.add(iframe);
}
Related
With Wicket 7, I am working on an app that uses a base page as a template for other pages to extend.
On the base page, I want to have a label and a link that changes depending on whether the user is authenticated or not.
Here's my BasePage.html:
<div wicket:id="chromeMenu">foo</div>
<div>
<h2 wicket:id="userGreeting"></h2>
<h2><span wicket:id="loginLabel"></span> </h2>
</div>
<wicket:child/>
and the BasePage.java:
public BasePage() {
super();
add(new ChromeDropDownMenu("chromeMenu", buildMenu()));
add(new Label("pageTitle", new StringResourceModel("page.title", this, null)));
if(BasicAuthenticatedSession.get().isSignedIn()) {
// Do stuff here
} else {
add(new Label("userGreeting", "Hello Visitor"));
add(new Link("loginLink") {
#Override
public void onClick() {
setResponsePage(LoginPage.class);
}
});
add(new Label("loginLabel","Test"));
}
}
HomePage extends BasePage.
HomePage.html
<wicket:extend/>
HomePage.java
public class HomePage extends BasePage {
private static final long serialVersionUID = 1L;
public HomePage() {
super();
setPageTitle(new StringResourceModel("page.title", this, new Model<Serializable>("Admin")));
add(new Label("version", getApplication().getFrameworkSettings().getVersion()));
}
}
HomePage is the class returned by the Wicket application.
When I try to load HomePage, I get the following error:
Last cause: Unable to find component with id 'loginLabel' in [Link [Component id = loginLink]]
Expected: 'loginLink:loginLabel'.
Found with similar names: 'loginLabel'
It points to the <a><span/></a> structure from BasePage.html as the root of the problem.
I've tried a few ways to work around this, but without success. I thought maybe an add(Link).add(Label) might be needed, but that didn't work either.
Any thoughts out there on what I'm missing?
The error message says it all.
Last cause: Unable to find component with id 'loginLabel' in [Link
[Component id = loginLink]]
Expected: 'loginLink:loginLabel'.
Found with similar names: 'loginLabel'
Wicket is expecting the same component hierarchy in your Java code as you've written in the HTML. In BasePage.html you have:
<h2><span wicket:id="loginLabel"></span> </h2>
In the BasePage.java code you need to add loginLabel as a child of loginLink component.
Link loginLink = new Link("loginLink") {
#Override
public void onClick() {
setResponsePage(LoginPage.class);
}
};
add(loginLink);
loginLink.add(new Label("loginLabel", "Test"));
The problem is at
add(new Link("loginLink") {
#Override
public void onClick() {
setResponsePage(LoginPage.class);
}
});
add(new Label("loginLabel","Test"));
The Link should be the parent of the Label:
link = new Link("loginLink") {
#Override
public void onClick() {
setResponsePage(LoginPage.class);
}
};
link.add(new Label("loginLabel","Test"));
add(link);
Few extra notes:
better use BookmarkablePageLink if setResponsePage() is the only thing you need in onClick()
use AbstractLink#setBody(IModel label) instead of Link+Label
I am building a GWT application.
In this application I have a number of DataGrid implementations showing data retrieved from the server. In one panel I have a TabLayoutPanel, with a DataGrid on each tab.
I am attempting to lazy-load the DataGrids when the parent tab becomes visible.
Here is the ui.xml:
<g:TabLayoutPanel width="800px" height="450px" barUnit='EM' barHeight='3'>
<g:tab>
<g:header size='7'><b>Volunteer Assignments</b></g:header>
<grid:VolunteerAssignmentGrid/>
</g:tab>
<g:tab>
<g:header size='7'><b>Volunteer Details</b></g:header>
<g:LazyPanel ui:field="lazyDetails">
<grid:VolunteerFieldsGrid/>
</g:LazyPanel>
</g:tab>
</g:TabLayoutPanel>
In the above code, VolunteerAssignmentGrid and VolunteerFieldsGrid are sub-classes of DataGrid.
The VolunteerAssignmentGrid is visible immediately and the data displays OK.
However, the VolunteerFieldsGrid on the next tab does not display at all.
The strange thing is, it is requesting the data at the correct time (when I click on the other tab), and the server response is correct. It's as if the table is not visible.
Any ideas why the second DataGrid is not visible?
EDIT:
The UiBinder class:
public class VolunteerDetailsPanel extends DialogBox {
interface Binder extends UiBinder<Widget, VolunteerDetailsPanel> {}
private static final Binder binder = GWT.create(Binder.class);
#UiField LazyPanel lazyDetails;
private Record volunteerRecord;
private String fullName;
private String volunteerId;
public VolunteerDetailsPanel(Record record) {
this.volunteerRecord = record;
fullName = volunteerRecord.getValue("forename")+" "+volunteerRecord.getValue("surname");
volunteerId = volunteerRecord.getValue("id");
setText(fullName);
}
public void initComponent() {
setWidget(binder.createAndBindUi(this));
}
#UiFactory VolunteerAssignmentGrid createAssignmentGrid() {
return new VolunteerAssignmentGrid(volunteerId, fullName);
}
#UiFactory VolunteerFieldsGrid createFieldsGrid() {
return new VolunteerFieldsGrid(volunteerId);
}
}
As requested, also the VolunteerFieldsGrid class. It extends ListGrid (one of mine, but too long to post here, all my other Grids extend it and are OK), which in turn extends GWT's DataGrid:
public class VolunteerFieldsGrid extends ListGrid {
public VolunteerFieldsGrid(String volunteerId) {
super(100, "name", false);
setWidth("100%");
ListGridColumn<?>[] columns = new ListGridColumn<?>[] {
new FieldNameColumn("Field", "name").width(75),
new TextColumn("Value", "value").width(300)
};
setColumns(columns);
ListGridDataProvider data = ListGridDataProvider.getInstance("field",
"/volunteer/"+volunteerId, "name", false);
setDataProvider(data);
}
}
You have to register a handler for SelectionEvent in the TabLayoutPanel that will call LazyPanel.setVisible(true). Try something like this in UiBinder:
#UiHandler("yourTabPanelUiField")
void onSelectionEvent(SelectionEvent event) {
//for extra functionality check if EventTarget equals the correct tab
lazyDetails.setVisible(true);
}
I have built a wicket component that contains input/labels and methods to change presentation (required, enabled, etc.). The components render fine, but what happens is when the form submits I see only 1 form parameter 'input', and it's the last InputRow component.
InputRow.html
<html xmlns:wicket="http://wicket.apache.org">
<head>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<wicket:panel>
<label wicket:id="label">abc: <span class="req">*</span></label>
<span class="input">
<input wicket:id="input" type="text" id="name"></input>
</span>
<span wicket:id="input_feedback"></span>
</wicket:panel>
</body>
</html>
InputRow.java
package com.wicket;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.feedback.FeedbackMessage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;
public class InputRow extends Panel{
#SuppressWarnings("unused")
private String id;
public InputRow(String id, String label) {
super(id);
this.id = id;
Label memberIdLabel = new Label("label",label);
memberIdLabel.setEscapeModelStrings(false)
.add(new AttributeAppender("for", new Model<String>(id),""));
add(memberIdLabel);
TextField<String> name = new TextField<String>("input");
name.setType(String.class)
.setMarkupId(id)
.setOutputMarkupId(true);
add(name);
add(new Label("input_feedback",""));
}
public InputRow disable()
{
get("input")
.setEnabled(false)
.add(new AttributeAppender("class", new Model<String>("disabled"),""));
get("label")
.add(new AttributeAppender("class", new Model<String>("disabled"),""));
return this;
}
public InputRow required()
{
Model model = (Model)get("label").getInnermostModel();
StringBuffer label = new StringBuffer((String)model.getObject());
label.append(" <span class=\"req\">*</span>");
model.setObject(label);
((TextField)get("input")).setRequired(true);
return this;
}
#Override
protected void onBeforeRender() {
super.onBeforeRender();
Label feedback = (Label)get("input_feedback");
if (get("input").getFeedbackMessage() != null)
{
feedback.setDefaultModel(new Model<String>("Required"));
}
}
}
Adding to the form component
add(new InputRow("name","Name:").required());
edit
I didn't set up a ListView or repeater since I know what rows / fields I want to add to the form at build time.
Your InputFields are missing their models. This way, wicket doesn't know where to store the formdata. If you add models to the fields they will be populated automatically.
There's not just one form parameter submitted. The submits are of the named like name:input, name2:input, ...
But as Nicktar suggests in the comment you should use a model to bind the value of the form component to your entity object. You have to accept an IModel in the constructor and use it in the constructor of TextField.
A better approach to what you are trying to do is to write a Behavior which adds decorating markup for your FormComponent. That way it works for more than just simple text input fields and you can fully customize the instances of your FormComponents.
It could look like this:
public class FormComponentBehavior extends Behavior {
#Override
public void bind(Component component) {
if (!(component instanceof FormComponent)) {
throw new IllegalArgumentException();
}
}
#Override
public void beforeRender(Component component) {
FormComponent<?> fc = (FormComponent<?>) component;
Response r = component.getResponse();
r.write("<label" + (fc.isRequired() ? " class='required'" : "") + ">");
r.write(fc.getLabel().getObject());
r.write("</label>");
r.write("<span class='input'>");
}
#Override
public void afterRender(Component component) {
component.getResponse().write("</span>");
// if feedback errors write them to markup...
}
}
Then you have to add this behavior to your FormComponent instances.
Maybe the problem with your form is that your input text fields have all the same id. Try using attribute 'name' instead of 'id'
I am trying to debug an issue with the following code:
<h:panelGroup id="items">
<ui:repeat value="#{itemController.items}" var="item">
<h:form>
<h:inputText id="title" value="#{item.fields['Title']}"/>
<a4j:commandButton action="#{dao.storeItem(item)}" value="Save" render="#form"/>
</h:form>
</ui:repeat>
</h:panelGroup>
The above works if a collection is displayed in the view directly. However, if the ui:repeat starts empty, and items are added through an AJAX request, and the ui:repeat rerendered, the forms break. Specifically the model is not updated, nor actions triggered. I want to understand why.
Right now my guess is that if the ui:repeat starts empty, the form component is not created at all. Can anyone verify this, or provide the correct explanation?
ADDITIONAL INFO
Here are relevant parts of the controller, I have also tried ViewScoped, and long-running conversations:
#Named
#ConversationScoped
public class ItemController implements Serializable
{
private static final long serialVersionUID = 1L;
#Inject
private HibernateDAO dao;
public List<Item> getItems()
{
return dao.getItems();
}
public void uploadListener(final FileUploadEvent event)
{
final UploadedFile item = event.getUploadedFile();
final FacesContext context = FacesContext.getCurrentInstance();
final Application application = context.getApplication();
final String messageBundleName = application.getMessageBundle();
final Locale locale = context.getViewRoot().getLocale();
final ResourceBundle resourceBundle = ResourceBundle.getBundle(messageBundleName, locale);
final String msg = resourceBundle.getString("upload.failed");
final String detailMsgPattern = resourceBundle.getString("upload.failed_detail");
try
{
CSVImporter.doImport(item.getInputStream(), dao, item.getName());
}
catch (ParseException e)
{
final Object[] params = {item.getName(), e.getMessage()};
final String detailMsg = MessageFormat.format(detailMsgPattern, params);
final FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, detailMsg);
context.addMessage("uploadForm:uploader", facesMsg);
}
catch (TokenMgrError e)
{
final Object[] params = {item.getName(), e.getMessage()};
final String detailMsg = MessageFormat.format(detailMsgPattern, params);
final FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, detailMsg);
context.addMessage("uploadForm:uploader", facesMsg);
}
}
}
The dao simple fetches the items from a database. Here is the relevant fileupload code:
<h:form id="uploadForm" enctype="multipart/form-data">
<h:message id="message" showDetail="true" for="uploader" errorClass="error" warnClass="warning" infoClass="info" fatalClass="fatal"/>
<rich:fileUpload id="uploader"
fileUploadListener="#{itemController.uploadListener}"
maxFilesQuantity="1"
acceptedTypes="csv"
render="items message" />
</h:form>
Okay posting it here because it will be longer than comments .
It works for me which is probably not what you wanted to hear :( but I had to teak few minor things . Firstly in controller add
public void storeItems(Item item)
{
dao.storeItems();
}
then change this
<a4j:commandButton action="#{dao.storeItem(item)}" value="Save" render="#form"/>
to
<a4j:commandButton action="#{itemController.storeItem(item)}" value="Save" render="#form"/>
That however is probably not the real issue and I think that is around here
CSVImporter.doImport(item.getInputStream(), dao, item.getName());
basically I am expecting that the method above would have uploaded data from where dao.getItems(); can fetch it. So put a breakpoint at public List<Item> getItems() and once file has been upload and render="items message" renders the items panel group again it should will hit this method and at that time see if dao.storeItems() is bringing any data back which it should. Reply back then and we will take it from there.
Update below to avoid running dao fetch twice.
You can not avoid two calls to your get thats part of JSF lifeCycle and is normal.
How ever you can avoid hitting the database twice as you should too but refactoring your code along the lines of
private List<Item> items;
public List<Item> getItems()
{
return items;
}
#PostConstruct
public void init()
{
this.items = dao.getItems();
}
public void uploadListener(FileUploadEvent event) throws Exception{
......
CSVImporter.doImport(item.getInputStream(), dao, item.getName());
this.items = dao.getItems();
.....
}
I have a <div id="test"><input type="button" value="OK" /></div> html tag.
I used:
((HasClickHandlers)RootPanel.get("test").getWidget(0)).addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
Window.alert('sss');
}
}
I executed but no action.
Update:
package com.example.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.*;
import com.google.gwt.user.client.*;
import com.google.gwt.user.client.ui.RootPanel;
public class ExampleWebApp implements EntryPoint {
public void onModuleLoad() {
((HasClickHandlers) RootPanel.get("test").getWidget(0)).addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
Window.alert("i got it");
}
});
}
}
HTML:
<table>
<tr>
<div id="test">
<input type=button onClick="" value='click here'>
</div>
</tr>
</table>
The GWT Button widget is a button tag and not a input tag. Which means you can't use the GWT Button widget in this case. To make it work you need to create your own widget, which can be based on the widget ButtonBase, but needs to be initialized with an InputElement object instead of a ButtonElement.
The next step to get tag from html is to add something similar to the static wrap method present in most widgets. Here is how it would be used in your example when the input would have been a button tag:
Button.wrap(RootPanel.get("test").getWidget(0).getElement()).addClickHandler(
new ClickHandler() {
#Override public void onClick(ClickEvent event) {
Window.alert('sss');
}
});
In you case you could add a wrap method to your custom input widget. See the Button widget implementation of te wrap method, it's the same, expect of course for the creation of the widget itself.
You can't just take an html button and try to add click handlers to it. You need to create the button using gwt code. Try:
<div id="test"></div>
And then:
Button button = new Button("OK");
RootPanel.get("test").add(button);
button.addClickHandler(new ClickHandler() {...});