i am using jsf and i am trying to show a hidden panel this what i tried
<h:commandButton update=":outPanel" actionListener="#{SelectBean.mod1()}" image="Ressources/images/update.png" style="vertical-align:middle" >
Modifier
</h:commandButton>
<p:panel visible="#{SelectBean.bol}" closable="true" toggleable="true" id="outPanel" styleClass="outPanel" widgetVar="outpanel">
<h:outputLabel value="Nom " />
<h:inputText value="#{SelectBean.nom}" />
<br/>
<h:outputLabel value="Experience " />
<h:inputText value="#{SelectBean.exp}" />
<br/>
<h:commandButton value="Modifier"/>
</p:panel>
my bean is
private boolean bol=false;
public boolean getBol() {
return bol;
}
public void setBol(boolean bol) {
this.bol = bol;
}
public String mod1()
{
bol = true;
return "success";
}
but this thing not working the panel is always hidden.
Try like this, your panel will be shown if bol is true
<p:panel rendered="#{selectBean.bol}" closable="true" toggleable="true" id="outPanel" styleClass="outPanel" widgetVar="outpanel">
Also i think you have wrong syntax, you should call methods and variables of your class through selectBean but not SelectBean
Related
I have many panelGrid's, I want to open a dialog when I click on panelGrid.
The problem is always selected the last panelGrid.
index.xhtml
<p:dataGrid var="object" value="#{vc.objects}"
layout="grid" id="dataGridObject">
<h:panelGrid columns="1" onclick="rc()">
<h:outputText value="#{object.name} " />
<p:remoteCommand name="rc" update="formX"
oncomplete="PF('dlgDetails').show()" action="#{vc.updateSelectObject(object)}"/>
</h:panelGrid>
</p:dataGrid>
ViewController.java
private Object selectObject;
public void updateSelectObject(Object object){
setSelectObject(object);
}
public Object getSelectObject() {
return selectObject;
}
public void setSelectObject(Object selectObject) {
this.selectObject = selectObject;
}
Why don't you try another approach. In this case with dataGrid you can replace outputText and remoteCommand with commandButton and you can style your button to look just like a panel.
<p:dataGrid var="object" value="#{vc.objects}"
layout="grid" id="dataGridObject" columns="1">
<p:commandButton value="#{object.name}"
actionListener="#{vc.updateSelectObject(object)}" process="#this"
update="formX" oncomplete="PF('dlgDetails').show()" />
</p:dataGrid>
I have an issue where I have a primefaces outputtext field and from the managed bean, I'm attempting to return an array type back to this field. Something is amiss in that I'm getting no return value back to my outputtext field. I will admit that I'm a bit rusty on my Java coding skills and it could be that I'm not performing something correctly within my bean method with respect to my return value.
My JSF page outputtext field
<p:panel id="horizontal" header="Conversion from Lat Long to MGRS" toggleable="true" toggleOrientation="horizontal">
<h:panelGrid columns="2" cellpadding="10" styleClass="left">
<h:outputLabel for="lat" value="Enter Latitude:" />
<p:inplace id="lat">
<p:inputText value="Latitude" />
</p:inplace>
<h:outputLabel for="long" value="Enter Longitude:" />
<p:inplace id="long">
<p:inputText value="Longitude" />
</p:inplace>
<h:outputLabel for="mgrs" value="MGRS conversion value:" />
<h:outputText id="mgrs" value="#{coordinates.MGRSCoordreturn}" />
<p:commandButton value="Submit" update="mgrs" icon="ui-icon-check" actionListener="#{coordinates.mgrsFromLatLon(lat, long)}"/>
</h:panelGrid>
</p:panel>
<h:outputLabel for="mgrs_input" value="Enter MGRS:" />
<p:inplace id="mgrs_input">
<p:inputText value="MGRS" />
</p:inplace>
<h:outputLabel for="mgrs_output" value="Lat Long conversion values:" />
<h:outputText id="mgrs_output" value="#{coordinates.latLongVReturn}" />
<p:commandButton value="Submit" update="mgrs_output" icon="ui-icon-check" actionListener="#{coordinates.latLonFromMgrs(mgrs_input)}"/>
My managed bean code:
#ManagedBean
#SessionScoped
public class Coordinates implements Serializable{
private String MGRSCoordreturn;
private Double LatLongVReturn;
public String mgrsFromLatLon(double lat, double lon){
// 37.10, -112.12
Angle latitude = Angle.fromDegrees(lat);
Angle longitude = Angle.fromDegrees(lon);
MGRSCoordreturn = MGRSCoord.fromLatLon(latitude, longitude).toString();
return MGRSCoord.fromLatLon(latitude, longitude).toString();
}
public String getMGRSCoordreturn() {
return MGRSCoordreturn;
}
public void setMGRSCoordreturn(String MGRSCoordreturn) {
this.MGRSCoordreturn = MGRSCoordreturn;
}
public double[] latLonFromMgrs(String mgrs){
MGRSCoord coord = MGRSCoord.fromString("31NAA 66021 00000");
double LatLongVReturn[] = new double[]{
coord.getLatitude().degrees,
coord.getLongitude().degrees
};
return new double[]{
coord.getLatitude().degrees,
coord.getLongitude().degrees
};
}
public Double getLatLongVReturn() {
return LatLongVReturn;
}
public void setLatLongVReturn(Double LatLongVReturn) {
this.LatLongVReturn= LatLongVReturn;
}
}
InputText field in the following dialog retains previous value even though I set it to blank before calling show(). The inputText field is only displayed blank when show() is called for the first time. My bean is session scoped.
<p:dialog id="dlgId" widgetVar="dlgVar" dynamic="true">
<h:form>
<h:panelGrid columns="1">
<h:outputLabel for="nametext" value="Name" />
<p:inputText id="nametext" value="#{myBean.name}" />
</h:panelGrid>
<p:commandButton value="Save" actionListener="#{myBean.saveAction}" />
</h:form>
public void add(TreeNode selectedTreeNode) {
setName("");
RequestContext.getCurrentInstance().execute("PF('dlgVar').show()");
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
How can I get the inputTEext field to display the value I set before calling show() rather then the value previously entered by the user?
The thing is: you need to update your form. To make it, you can use one of these solutions.
Solution 1 : update it from your xhtml
<h:form id="form">
<h:panelGrid columns="1">
<h:outputLabel for="nametext" value="Name" />
<p:inputText id="nametext" value="#{myBean.name}" />
</h:panelGrid>
<p:commandButton value="Save" actionListener="#{myBean.saveAction}" update=":form" />
</h:form>
Solution 2 : update it from your managedBean
YourXhtml
<h:form id="form">
...
</h:form>
YourManagedBean
public void saveAction() {
...
name = "";
RequestContext.getCurrentInstance().update(":form");
}
You can also read this post Can I update a JSF component from a JSF backing bean method?.
Solution 3 : update it using an Ajax event
You can also add an ajax event
<p:commandButton value="Save" type="button" >
<p:ajax event="click" listener="#{myBean.saveAction}" update=":form"/>
</p:commandButton>
Sidenote: It works with Command-Buttons.
What I Have:
A simple form where name and address from a customer are entered. In a data-table below, each row contained (in the working version) the following fields:
Name of the customer
A Command-Button which redirects to another page and shows the customers orders (This worked using <p: commandButton immediate="true">)
Another Command-Button which displayed the past orders.
Another Command-Button which was responsible for updating customer-data.
Since I didn't want to have three Command-Buttons in each row I decided to use a Split-Button.
Problem:
<p:splitButton immediate="true">
The form asks me to fill the missing data (name and address) which are set to required="true.
Question:
As far as I understand the attribute immediate="true is used to overcome this issue. So what am I missing ?
Code:
<h:form>
<p:growl id="growl" sticky="false" life="3500" showDetail="false"/>
<h:panelGrid id="customer_grid" columns="2" cellspacing="1" cellpadding="5">
<h:outputLabel id="label" for="name" value="Kunde:" style="font-weight:bold"/>
<p:inputText id="name" value="#{customerController.customer.name}" required="true" requiredMessage="Name eingeben!"/>
<h:outputLabel for="address" value="Adresse:" style="font-weight: bold" />
<p:inputText id="address" value ="#{customerController.customer.address}" required="true" requiredMessage="Adresse eingeben!"/>
<p:commandButton action = "#{customerController.createCustomer}" value="Speichern" style="margin-right:10px"
actionListener="#{growlController.saveMessage}" ajax="true"
onclick="PF('blockUIWidget').block()" oncomplete="PF('blockUIWidget').unblock()" styleClass="save-button"/>
<p:commandButton onclick="history.back(); return false;" value="Abbrechen" ajax="true"/>
<pe:blockUI widgetVar="blockUIWidget">
<h:panelGrid columns="2">
<p:graphicImage id="loader" name="images/ajax-loader.gif" style="margin-right: 12px; vertical-align: middle;" rendered="true"/>
<h:outputText value="Please wait..." style="white-space: nowrap;"/>
</h:panelGrid>
</pe:blockUI>
</h:panelGrid>
<br/>
<br/>
<p:dataTable var="customer" value="#{customerController.allCustomers}" resizableColumns="true" tableStyle="width: auto"
rendered="#{not empty customerController.allCustomers}">
<p:column headerText="customer" style="width: 300px">
<h:outputText value="#{customer.name}" />
</p:column>
<p:column>
<p:splitButton value="current order" action="#{userController.setup(customer, 'lastOrder')}" immediate="true">
<p:menuitem value="old orders" action="#{userController.setup(customer, 'oldOrders')}" immediate="true"/>
<p:menuitem value="edit" action="#{userController.setup(customer, 'update')}" immediate="true"/>
</p:splitButton>
</p:column>
</p:dataTable>
EDIT:
According to the comment of BalusC I've put the two parts in separate forms.
Effect: The message to fill out the above form does not show up, but the redirect is not happening either.
EDIT2:
The purpose of the method userController.setup(customer, 'String') is basically to inject the customer who is represented for each row. The String is returned for redirecting purposes which are set in the faces-config.xml and as I said: It works when I use Command-Buttons instead.
CODE:
#Named
#SessionScoped
public class UserController implements Serializable{
#Inject
private Customer customer;
#EJB
private CustomerService customerService;
public UserController(){
}
public List<Item> getItems(){
return customerService.getItems(customer);
}
public Ordery getCurrentOrder(){
return customerService.getCurrentOrder(customer);
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public CustomerService getCustomerService() {
return customerService;
}
public void setCustomerService(CustomerService customerService) {
this.customerService = customerService;
}
public String setup(Customer customer, String nav){
this.customer = customer;
return nav;
}
public void update(){
customerService.update(customer);
}
}
I have a jsf page that I can't update the value of some checkboxes in a list of userDamain objects, in fact this is a part of my jsf page :
<h:outputText value="USER's rights list: "></h:outputText>
<p:dataTable id="userss" var="userr" value="#{userMB.userListe}">
<p:column>
<f:facet name="header"><h:outputText value="FirstName" /></f:facet>
<h:outputText value="#{userr.firstName}" />
</p:column>
<p:column>
<h:panelGrid columns="1" style="margin-bottom:10px" cellpadding="5">
<h:outputText value="Basic Usage: " />
<p:selectBooleanCheckbox value="#{userr.deletee}" immediate="true" actionListener="#{userr.deletee}" />
</h:panelGrid>
<p:commandButton value="Submit" update="display" oncomplete="dlg.show()" />
<p:dialog header="Selected Values" modal="true" showEffect="fade" hideEffect="fade" widgetVar="dlg">
<h:panelGrid columns="1" id="display">
<h:outputText value="Value 1: #{userr.deletee}" />
</h:panelGrid>
</p:dialog>
</p:column>
when I click on the boolean button 'Submit', the value of the userr.deletee is always false ( the default value ) and it's not updated anyway, I tried to use the Listner and actionListener in the booleanButton but it doesn't work, I also tried the postValidate event, so if someone has any idea of that, I would be graceful.
this is a part of my managed bean:
private List<UserDomain> userListe ;
public List<UserDomain> getUserListe() {
return this.userListe;
}
public void loadUserListe(){
this.userListe = new ArrayList<UserDomain>();
this.userListe.addAll(getUserServicee().getAll());
}
public void setUserListe(List<UserDomain> userListe) {
this.userListe = userListe;
}
a part of the userDomain bean:
...
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
#Transient
private boolean deletee;
public boolean isDeletee() {
return deletee;
}
public void setDeletee(boolean deletee) {
this.deletee = deletee;
}
I found out a solution which seems logic to me, I added to my checkbox an ajax behavior to execute a method and an attribute which called in this method to get the whole userDomain object, so on I can get the user.deletee value, here is a part of the code I m talking about:
<h:panelGrid columns="1" style="margin-bottom:10px" cellpadding="5">
<h:outputText value="Delete Right: " />
<p:selectBooleanCheckbox value="#{userr.deletee}">
<f:ajax execute="#this" listener="#{userMB.saveUserRights}" />
<f:attribute name="user" value="#{userr}" />
</p:selectBooleanCheckbox>
</h:panelGrid>
I hope this will be helpful for you