Portal Showcase
portal:inputRichText
InputRichText is a UIInput component that renders a field for editing rich text.Immediate Usage
When the immediate attribute istrue
, the submitted value is converted and validated during APPLY_REQUEST_VALUES phase of the JSF lifecycle, rather than the normal PROCESS_VALIDATIONS phase.
ソースコード
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:portal="http://liferay.com/faces/portal"> <!-- Example 1: ValueChangeListener execution when immediate is true --> <h:form> <h:messages id="messages" globalOnly="true" styleClass="feedback" /> <h:message id="commentsMessage" for="comments" /> <portal:inputRichText id="comments" immediate="true" value="#{inputRichTextBacking.applicant.comments}" valueChangeListener="#{inputRichTextBacking.valueChangeListener}" /> <h:commandButton actionListener="#{inputRichTextBacking.submit}" value="#{i18n['submit']}"> <f:ajax execute="@form" render="messages :modelValue1" /> </h:commandButton> </h:form> <h:outputText id="modelValue1" value="#{inputRichTextBacking.applicant.comments}" /> <!-- Example 2: ValueChangeListener execution when immediate is false (the default) --> <h:form> <h:messages id="messages" globalOnly="true" styleClass="feedback" /> <h:message id="commentsMessage" for="comments" /> <portal:inputRichText id="comments" value="#{inputRichTextBacking.applicant.comments}" valueChangeListener="#{inputRichTextBacking.valueChangeListener}" /> <h:commandButton actionListener="#{inputRichTextBacking.submit}" value="#{i18n['submit']}"> <f:ajax execute="@form" render="messages :modelValue2" /> </h:commandButton> </h:form> <h:outputText id="modelValue2" value="#{inputRichTextBacking.applicant.comments}" /> </ui:composition>
@ManagedBean @RequestScoped public class InputRichTextBacking { private static final Logger logger = LoggerFactory.getLogger(InputRichTextBacking.class); private Applicant applicant; private boolean resizable = true; public Applicant getApplicant() { return applicant; } @PostConstruct public void init() { applicant = new Applicant(); if (ViewParamUtil.getUsage().equals("default-value")) { applicant.setComments( "<p>This is some <strong>bold</strong> text<br />\nand this is some <em>italic</em> text.</p>"); } } public boolean isResizable() { return resizable; } public void setResizable(boolean resizable) { this.resizable = resizable; } public void submit() { logger.info("You entered comments: " + applicant.getComments()); } public void valueChangeListener(ValueChangeEvent valueChangeEvent) { FacesContext facesContext = FacesContext.getCurrentInstance(); PhaseId phaseId = facesContext.getCurrentPhaseId(); logger.debug("valueChangeListener: phaseId=[{0}]", phaseId.toString()); String phaseName = phaseId.toString(); FacesMessage facesMessage = new FacesMessage("The valueChangeListener method was called during the " + phaseName + " phase of the JSF lifecycle."); facesContext.addMessage(null, facesMessage); } }
public class Applicant implements Serializable { private static final long serialVersionUID = 4661552363081858711L; private String city; private String comments; private Date dateOfBirth; private String emailAddress; private String firstName; private String lastName; private String phoneNumber; private String postalCode; private Long provinceId; public String getCity() { return city; } public String getComments() { return comments; } public Date getDateOfBirth() { return dateOfBirth; } public String getEmailAddress() { return emailAddress; } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public String getPhoneNumber() { return phoneNumber; } public String getPostalCode() { return postalCode; } public Long getProvinceId() { return provinceId; } public void setCity(String city) { this.city = city; } public void setComments(String comments) { this.comments = comments; } public void setDateOfBirth(Date dateOfBirth) { this.dateOfBirth = dateOfBirth; } public void setEmailAddress(String emailAddress) { this.emailAddress = emailAddress; } public void setFirstName(String firstName) { this.firstName = firstName; } public void setLastName(String lastName) { this.lastName = lastName; } public void setPhoneNumber(String phoneNumber) { this.phoneNumber = phoneNumber; } public void setPostalCode(String postalCode) { this.postalCode = postalCode; } public void setProvinceId(Long provinceId) { this.provinceId = provinceId; } }
Liferay Faces Bridge Implementation 5.0.0 + Liferay Faces Portal 5.0.0 + Showcase Common 3.1.1 + Liferay Faces Util 3.4.1 + Mojarra 2.2.20