<h:form>
<p:dashboard id="board"
binding="#{fundamentFormCreatorBean.dashboard}">
</p:dashboard>
</h:form>
FacesContext fc = FacesContext.getCurrentInstance();
Application application = fc.getApplication();
dashboard = (Dashboard) application.createComponent(fc,
"org.primefaces.component.Dashboard",
"org.primefaces.component.DashboardRenderer");
dashboard.setId("dashboard");
DashboardModel model = new DefaultDashboardModel();
column1 = new DefaultDashboardColumn();
Panel panel = (Panel) application.createComponent(fc,
"org.primefaces.component.Panel",
"org.primefaces.component.PanelRenderer");
panel.setId("UniqueId");
panel.setHeader("panelName");
panel.setClosable(true);
dashboard.getChildren().add(panel);
column1.addWidget(panel.getId());
I want to add a f:facet to a panel from bean.I have added Primefaces dashboard and its panels dynamically from bean shown in the above code. I tried to add a facet with the below code but didn't work out.
HtmlGraphicImage oTabImage= new HtmlGraphicImage();
oTabImage.setValue("/images/tabicon.jpg");
HtmlOutputText oText = new HtmlOutputText();
oText.setValue("Here is my label");
HtmlPanelGroup oGroup = new HtmlPanelGroup();
oGroup.getChildren().add(oText);
oGroup.getChildren().add(oTabImage);
panel.getFacets().put("label", oGroup);
The PrimeFaces panel does not have the label facet. So this will never work, not even in xhtml (as stated by me). Try the header facet, that will work
Related
I have a xhtml page with a session scoped backing bean. Now i have to open this page in a new tab with right click open link in new tab.
When this page opens the model class of the backing bean must be cleared.
I have used the following code:
<p:menuitem value="Details" action="#{beanMB.clearDetailModel()}"/>
backing bean code:
public void clearDetailModel()
{
memberModel=null;
......
return "/pages/member/MemberDetails.xhtml?faces-redirect=true";
}
The above code clears the session scoped model but it does not open the page in new tab.
Is there any method to open the page in new tab with the above code or is there any alternate way for the above problem?.Any help would be appreciated.
Thank you.
You can try this:
You need to put the following code in MemberDetails.xhtml page.
<f:metadata>
<f:event type="preRenderView" listener="#{beanMB.clearDetailModel}"/>
</f:metadata>
and use url in menuitem to open your page.
<p:menuitem value="Details" url="/pages/member/MemberDetails.xhtml" />
you need to modify your backing bean code as follows:
public void clearDetailModel()
{
if (isNewRequest()){
memberModel=null;
......
}
}
public boolean isNewRequest() {
final FacesContext fc = FacesContext.getCurrentInstance();
final boolean getMethod = ((HttpServletRequest) fc.getExternalContext().getRequest()).getMethod().equals("GET");
final boolean ajaxRequest = fc.getPartialViewContext().isAjaxRequest();
final boolean validationFailed = fc.isValidationFailed();
return getMethod && !ajaxRequest && !validationFailed;
}
Here method isNewRequest() checks if the request is new or not if this is not checked your method clearDetailModel() will be called each time new request is made.
I have created jsf form at backing bean. I have created form, it is being shown on screen with values successfully. When I click sumbit button, backing bean method is invoked with ActionEvent but updated input values are not submitted to backend. Backign bean entity object values are not updated.
Is there any wrong? Thanks so much for your helps,
Br.
Ramazan
HtmlForm form = new HtmlForm();
form.setId(appletWrapper.getName()+"_FORM");
PanelGrid panelGrid = (PanelGrid)createComponent(PanelGrid.COMPONENT_TYPE);
form.getChildren().add(panelGrid);
panelGrid.setColumns(4);
panelGrid.setId(appletWrapper.getName()+"_FORM_PANEL");
for (FieldWrapper fieldWrapper : appletWrapper.getFields()) {
panelGrid.getChildren().add(new UIFieldLabel(fieldWrapper).component(entities));
panelGrid.getChildren().add(newFieldComponent(fieldWrapper, entities));
}
HtmlPanelGroup panelGroup = new HtmlPanelGroup();
panelGroup.setId(appletWrapper.getName()+"_PANEL_GROUP");
panelGrid.getFacets().put("footer", panelGroup);
CommandButton commandButton = new CommandButton();
panelGroup.getChildren().add(commandButton);
commandButton.setId(appletWrapper.getName()+"_UPDATE");
commandButton.setAjax(true);
commandButton.setValue("update");
commandButton.setProcess("#this");
commandButton.setType("submit");
MethodExpression updateEntityME = createMethodExpression("#{mainBean.entityUpdateListener}", null, new Class[] {ActionEvent.class });
commandButton.addActionListener(new MethodExpressionActionListener(updateEntityME));
return form;
Edited: I gave all components a fixed id.
One of my coponents genarated like that;
InputText inputText = (InputText)createComponent(InputText.COMPONENT_TYPE);
inputText.setId(fieldAlphanumericWrapper.getName());
inputText.setValueExpression("value", createValueExpression("#{mainBean.selection."+fieldAlphanumericWrapper.getProperty()+"}", Object.class));
return inputText;
My backing bean target method;
public void entityUpdateListener(ActionEvent actionEvent) {
TAccount tAccount = (TAccount)getSelection();
System.out.println("tAccount.gettWebsite():"+tAccount.gettWebsite());
}
The main problem is that actually; When I press commandButton mainBean.setSelection is not invoked, so backing bean object is not updated. I cant take updated object instance through actionEvent instance.
I found solution, cause of problem was this line;
commandButton.setProcess("#this");
I have changed to this and problem solved.
commandButton.setProcess("#form");
Br.
Ramazan
Using primeFaces I have the following button:
<p:commandButton value="Submit" action="#{createDeal.saveDeal}" update="myPanel" />
This works just fine. However I want to generate that button using java.
I have the following code:
CommandButton submit = new CommandButton();
submit.setValue("Submit");
submit.setUpdate("myPanel");
FacesContext facesCtx = FacesContext.getCurrentInstance();
Application app = facesCtx.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = facesCtx.getELContext();
MethodExpression methodExpression =null;
methodExpression = elFactory.createMethodExpression(elContext,"#{createDeal.saveDeal}",String.class, new Class[]{});
submit.addActionListener(new MethodExpressionActionListener(methodExpression));
submit.setActionExpression(methodExpression);
createButtons.getChildren().add(submit);
When I click submit, my form validates (which is done using the setRequired function on the input), but the form never hits my createDeal class. What am I doing wrong that the inline button works, but the java generated one does not.
One note. The button created inline using primefaces, is there on page load. The button attempted to be added with java is not done until after an Ajax call is made to generate both the form AND button.
Any assistance would be helpful.
Thanks.
Thanks to BalusC for all your help. I am still not sure how I missed this! The following works:
CommandButton submit = new CommandButton();
submit.setValue("Submit");
submit.setUpdate("myPanel");
submit.setId("create"+panelClass);
FacesContext facesCtx = FacesContext.getCurrentInstance();
ELContext elContext = facesCtx.getELContext();
Application app = facesCtx.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
MethodExpression methodExpression =null;
methodExpression = elFactory.createMethodExpression(elContext,"# {createDeal.saveDeal}",null, new Class[]{});
submit.setActionExpression(methodExpression);
createButtons.getChildren().add(submit);
The null pointer exception was unrelated. It looks like simply adding the ID and removing the ActionListener did the trick. Much obliged!
I have some fields of a bean that I need to show programmatically. Is something like this:
HtmlPanelGrid panel = new HtmlPanelGrid();
panel.setColumns(4);
HtmlOutputLabel fieldOut = new HtmlOutputLabel();
fieldOut.setId("fieldOutId");
fieldOut.setValue("name");
panel.getChildren().add(fieldOut);
HtmlInputText fieldIn = new HtmlInputText();
fieldIn.setId("fieldInId");
fieldIn.setPartialSubmit(true);
fieldIn.setValueExpression(
"field", UtilFaces.createValueExpression("#{newElementBean.fieldName}",String.class));
panel.getChildren().add(fieldIn);
mainForm.getChildren().add(panel);
In newElements.xhtml i've defined a form which is binded to mainForm, in this way:
<ice:form binding="#{newElementBean.mainForm}">
<ice:inputText id="ANOTHERFIELD" value="#{newElementBean.anotherField}"/>
<ice:commandButton action="#{newElementBean.save}" value="Save"/>
</ice:form>
When I click on the save button and I go to the next view, the field "ANOTHERFIELD" has taken the value from the bean, and shows up correctly, but the fields that were dinamically generated shows empty. Its values in the backing bean also are null. It's like the ValueExpression is not working for the HtmlInputText that I created in the backing bean. I'm using Icefaces 3.3 with Mojarra 2.1.17.
How is this caused and how can I solve it?
I solved it. I made two mistakes:
The proper setValueExpression call is like this:
fieldIn.setValueExpression("value", UtilFaces.createValueExpression("#newElementBean.fieldName}");
I was incorrectly using "field1" as 1st argument instead of "value".
This is not visble in the question, but my createValueExpression() helper method was also wrong. The following is working for me:
public static ValueExpression createValueExpression(String expression) {
Application app = FacesContext.getCurrentInstance().getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = FacesContext.getCurrentInstance().getELContext();
return elFactory.createValueExpression(elContext, expression, Object.class);
}
I am reasonably new to Java/JSF development (previously Mainframe legacy) so I am hoping someone will be able to let me know if what I am about to ask is possible and how to do it. Or at least point me in the right direction.
I'm trying to create a portlet where I can add the same component over and over again up to a maximum of 30 times. Eventually the data behind these components will be different in each one but from the same database. What I've done so far is create a container component and a button which calls a method to add something to the container. Like as follows:
<h:body>
<h:form>
<ice:panelGrid binding="#{simpleBean.containerComponent}"/>
<br/>
<ice:commandButton value="add new section" action="#{simpleBean.addComponent}" />
</h:form>
</h:body>
What I'm struggling with is the backing bean to create and render the component. At the minute I am just trying to create anything that repeats. The final code will be more complex than this.
private HtmlPanelGrid containerComponent;
private int i = 1;
public void addComponent() {
UIColumn uiColumn = new UIColumn();
uiColumn.setId("UIColumn_"+i);
HtmlOutputText htmlOutputText = new HtmlOutputText();
htmlOutputText.setId("HtmlOutputText_"+i);
htmlOutputText.setValue("HtmlOutputText_1_Value");
HtmlInputText htmlInputText = new HtmlInputText();
htmlInputText.setId("HtmlInputText_"+i);
htmlInputText.setValue("HtmlInputText_1_Value");
uiColumn.getChildren().add(htmlOutputText);
uiColumn.getChildren().add(htmlInputText);
if (containerComponent == null) {
containerComponent = new HtmlPanelGrid();
}
containerComponent.getChildren().add(uiColumn);
i++;
}
I can get the code to render something the first time the button is clicked but nothing happens subsequently. In an ideal world I'd get 30 of the same component displayed on the screen.
Can anyone offer any advice?
Thank you in advance.
Chris