How to add attributes to input fields in JSP - forms

How can I add the following attributes:
placeholder="text here"
required
data-parsley-type="number"
checked (only for he radio)
To the following inputs in a form:
<html:text property="text" value="text" />
<html:radio property="radio" value="1" />
<html:select property="text" value="1" />

Related

IBM Host On Demand Macro <condition> message warning action

I am trying to get 3 options condition, but I am going crazy:
In a specific field may appear a number, a text or be an empty field
Conditions:
if any text = warning message pops up: "This in an error "
if any number= [pagedown] action
if empty = warning message pops up: "pls change code "
May someone help me?
Thanks!
<HAScript name="new condition" description="" timeout="60000" pausetime="300" promptall="te" blockinput="false" author="gennaro" creationdate="Nov 19, 2022 8:07:14 PM" supressclearevents="false" usevars="true" ignorepauseforenhancedtn="true" delayifnotenhancedtn="0" ignorepausetimeforenhancedtn="true">
<vars>
<create name="$text$" type="string" value="" />
<create name="$num$" type="integer" value="0" />
<create name="$emptyfield$" type="field" />
</vars>
<screen name="Screen1" entryscreen="true" exitscreen="true" transient="false">
<description >
<oia status="NOTINHIBITED" optional="false" invertmatch="false" />
</description>
<actions>
<extract name="&apos;Extract&apos;" planetype="TEXT_PLANE" srow="6" scol="66" erow="6" ecol="70" unwrap="false" continuous="false" assigntovar="$text$" />
<extract name="&apos;Extract&apos;" planetype="TEXT_PLANE" srow="6" scol="66" erow="6" ecol="70" unwrap="false" continuous="false" assigntovar="$num$" />
<extract name="&apos;Extract&apos;" planetype="TEXT_PLANE" srow="6" scol="66" erow="6" ecol="70" unwrap="false" continuous="false" assigntovar="$emptyfield$" />
<if condition="$string$" >
<input value="" row="0" col="0" movecursor="true" xlatehostkeys="true" encrypted="false" />
<message title="$string$" value="" />
</if>
<if condition="$num$" >
<input value="&apos;[pagedn]&apos;" row="0" col="0" movecursor="true" xlatehostkeys="true" encrypted="false" />
</if>
<if condition="$emptyfield$" >
<message title="$emptyfield$" value="" />
</if>
</actions>
<nextscreens timeout="0" >
</nextscreens>
</screen>
</HAScript>
I was expecting
Conditions:
if any text = warning message pops up: "This in an error "
if any mumber= [pagedoen] action
if empty = warning message pops up: "pls change code "

SharePoint PnP - Adding fields to default view

I’m using the SharePoint PnP templates to deploy a list instance to SharePoint 2016. Is it possible to make the field “TheName” part of the default view or a particular view using an attribute?
Below I’ve set the “TheName” field attributes Viewable="true" ShowInDisplayForm="true" ShowInViewForms="true" but that has not resulted in “TheName” being part of the default view. Below is the xml for the list instance:
<pnp:ListInstance Title="Application" Description="" EnableAttachments="true" DocumentTemplate="" TemplateType="100" Url="Lists/Application" MinorVersionLimit="0" MaxVersionLimit="0" DraftVersionVisibility="0" TemplateFeatureID="00bfea71-de22-43b2-a848-c05709900100" ContentTypesEnabled="true" EnableFolderCreation="true">
<pnp:ContentTypeBindings>
<pnp:ContentTypeBinding ContentTypeID="0x0109413FF39DA2049E08C8B9564402E3562" Default="true" />
</pnp:ContentTypeBindings>
<pnp:Fields>
<pnp:Field Type="Text" DisplayName="TheName" StaticName="TheName" Name="TheName" Default="true" ID="{db2beb10-5325-434d-a559-691e340a4fea}" Viewable="true" ShowInDisplayForm="true" ShowInViewForms="true" />
</pnp:Fields>
</pnp:Views>
</pnp:ListInstance>
I can explicitly create/set the default view to include “TheName” but then I end up having to list all the fields that are part of the list including the ones which come from a site content type. This can become a hassle to maintain. The below list instance xml displays “TheName” as part of the default view:
<pnp:ListInstance Title="Application" Description="" EnableAttachments="true" DocumentTemplate="" TemplateType="100" Url="Lists/Application" MinorVersionLimit="0" MaxVersionLimit="0" DraftVersionVisibility="0" TemplateFeatureID="00bfea71-de22-43b2-a848-c05709900100" ContentTypesEnabled="true" EnableFolderCreation="true">
<pnp:ContentTypeBindings>
<pnp:ContentTypeBinding ContentTypeID="0x0109413FF39DA2049E08C8B9564402E3562" Default="true" />
</pnp:ContentTypeBindings>
<pnp:Fields>
<pnp:Field Type="Text" DisplayName="TheName" StaticName="TheName" Name="TheName" Default="true" ID="{db2beb10-5325-434d-a559-691e340a4fea}" Viewable="true" ShowInDisplayForm="true" ShowInViewForms="true" />
</pnp:Fields>
<pnp:Views>
<View DisplayName="All Items">
<ViewFields>
<FieldRef Name="TheName" />
<FieldRef Name="Title" />
<FieldRef Name="ApplicationId" />
<FieldRef Name="Case" />
</ViewFields>
</View>
</pnp:Views>
</pnp:ListInstance>

Cannot copy values from one Composite component to another JSF

I am having a pretty frustrating time trying to get values across components.
I am trying to do an address component that I can reuse, once for a residential address and once for a postal address. There is a selectOneCheck box which allows the user to specify that the residential address is the same as the postal address. I would like the the values of the first(residential address) component copied to the values of the second (postal address)component, then to disable the second component.
Here is my code for the composite component:
<composite:interface>
<composite:attribute name="addressLine1" required="true"
targets="addressLine1Text" />
<composite:attribute name="addressLine2" required="false"
targets="addressLine2Text" />
<composite:attribute name="addressLine3" required="false"
targets="addressLine3Text" />
<composite:attribute name="city" required="true" targets="cityText" />
<composite:attribute name="state" required="true" targets="stateText" />
<composite:attribute name="postCode" required="true"
targets="postCodeText" />
<composite:attribute name="styleClass" required="true" />
<composite:attribute name="disabled" required="true" />
<composite:attribute name="addressLine1Label" required="false"
targets="addressLine1Label" />
<composite:attribute name="addressLine2Label" required="false"
targets="addressLine2Label" />
<composite:attribute name="addressLine3Label" required="false"
targets="addressLine3Label" />
<composite:attribute name="cityLabel" required="false"
targets="cityLabel" />
<composite:attribute name="stateLabel" required="false"
targets="stateLabel" />
<composite:attribute name="postCodeLabel" required="false"
targets="postCodeLabel" />
<composite:implementation>
<composite:renderFacet name="heading"/>
<h:panelGrid columns="3">
<h:outputLabel id="addressLine1Label" for="addressLine1Text"
value="#{cc.attrs.addressLine1Label}" />
<h:inputText id="addressLine1Text" value="#{cc.attrs.addressLine1}" >
</h:inputText>
<h:message for="addressLine1Text" id="addressLine1Message" />
<h:outputLabel id="addressLine2Label" for="addressLine2Text"
value="#{cc.attrs.addressLine2Label}" />
<h:inputText id="addressLine2Text" value="#{cc.attrs.addressLine2}">
</h:inputText>
<h:message for="addressLine2Text" id="addressLine2Message" />
<h:outputLabel id="addressLine3Label" for="addressLine3Text"
value="#{cc.attrs.addressLine3Label}" />
<h:inputText id="addressLine3Text" value="#{cc.attrs.addressLine3}">
</h:inputText>
<h:message for="addressLine3Text" id="addressLine3Message" />
<h:outputLabel id="cityLabel" for="cityText"
value="#{cc.attrs.cityLabel}" />
<h:inputText id="cityText" value="#{cc.attrs.city}">
</h:inputText>
<h:message for="cityText" id="cityMessage" />
<h:outputLabel id="stateLabel" for="stateText"
value="#{cc.attrs.stateLabel}" />
<h:inputText id="stateText" value="#{cc.attrs.state}">
</h:inputText>
<h:message for="stateText" id="stateMessage" />
<h:outputLabel id="postCodeLabel" for="postCodeText"
value="#{cc.attrs.postCodeLabel}" />
<h:inputText id="postCodeText" value="#{cc.attrs.postCode}">
</h:inputText>
<h:message for="postCodeText" id="postCodeMessage" />
</h:panelGrid>
</composite:implementation>
Here is the the component in use :
<add:address
id="residentialAddress" styleClass="bold"
addressLine1="#{registrationBean.residentialAddress.addressLine1}"
addressLine2="#{registrationBean.residentialAddress.addressLine2}"
addressLine3="#{registrationBean.residentialAddress.addressLine3}"
city="#{registrationBean.residentialAddress.city}"
state="#{registrationBean.residentialAddress.state}"
postCode="#{registrationBean.residentialAddress.postCode}"
addressLine1Label="#{msgs.addressLine1}"
addressLine2Label="#{msgs.addressLine2}"
addressLine3Label="#{msgs.addressLine3}"
cityLabel="#{msgs.city}"
stateLabel="#{msgs.state}"
postCodeLabel="#{msgs.postCode}"
>
<f:facet name="heading">
<h:outputLabel value="#{msgs.residentialAddress}" />
</f:facet>
<f:converter for="add" converterId="myConvertor"/>
</add:address>
Here is the selectOneRadioButton:
<p:selectBooleanCheckbox
id="sameAsResidentialAddress"
itemLabel="#{msgs.sameAsResidentialAddress}"
valueChangeListener="#{registrationBean.sameAsResidentialAddress}"
>
<f:ajax execute="#form" render="postalAddress">
</f:ajax>
</p:selectBooleanCheckbox>
<h:message for="sameAsResidentialAddress"/>
Here is the component being resused for postal address:
<add:address id="postalAddress" styleClass="bold"
addressLine1="#{registrationBean.residentialAddress.addressLine1}"
addressLine2="#{registrationBean.postalAddress.addressLine2}"
addressLine3="#{registrationBean.postalAddress.addressLine3}"
city="#{registrationBean.postalAddress.city}"
state="#{registrationBean.postalAddress.state}"
postCode="#{registrationBean.postalAddress.postCode}"
addressLine1Label="#{msgs.addressLine1}"
addressLine2Label="#{msgs.addressLine2}"
addressLine3Label="#{msgs.addressLine3}" cityLabel="#{msgs.city}"
stateLabel="#{msgs.state}" postCodeLabel="#{msgs.postCode}"
rendered="#{!registrationBean.same}">
<f:facet name="heading">
<h:outputLabel value="#{msgs.postalAddress}" />
</f:facet>
<f:converter for="add" converterId="myConvertor"/>
</add:address>
The java code are a POJOs for Address and Registration. Registration has a valueChangeListener that sets a boolean to true if the sameAsResidentialAddress selectOneRadio is checked.
public void sameAsResidentialAddress(ValueChangeEvent event){
setSame((Boolean)event.getNewValue());
}
These components are on the same form named registration with no prepended id to them.
it roughly looks like this:
<h:form id="Registration">
<p:wizard>
<p:tab id ="address" title="Your Addresses">
<p:panel id="addresses">
<add:address id= "residentialAddress">
...
</add:address>
<p:selectBooleanCheckbox id="sameAsResidentialAddress">
...
</p:selectBooleanCheckbox>
<add:address id= "postalAddress">
...
</add:address>
</p:panel>
</p:tab>
</p:wizard>
</h:form>
I have tried my best to make my request as understandable as possible, and I hope you guys can understand what I am after. Please help me.
In the value change listener of the boolean check box you have to populate the postal address object which you are not doing. If both postal address and residential address are of the same type Address then you have to do
public void sameAsResidentialAddress(ValueChangeEvent event){
if((Boolean)event.getNewValue()) {
setSame((Boolean)event.getNewValue());
registrationBean.setPostalAddress(registrationBean.getResidentialAddress());
}
}
Hope this would help.
The problem was I did not completely understand the JSF lifecycle, I was updating my values the APPLY_REQUEST_VALUES phase instead of the INVOKE_APPLICATION phase. Also setting the postal address to the same object as the residential address is a bad idea because it end up with me not being able to update either one without affecting the other.
This works better.
public void sameAsResidentialAddress(ValueChangeEvent event) throws AbortProcessingException{
FacesContext context = FacesContext.getCurrentInstance();
if(context.getCurrentPhaseId() != PhaseId.INVOKE_APPLICATION){
event.setPhaseId(PhaseId.INVOKE_APPLICATION);
event.queue();
return;
}
if ((Boolean)event.getNewValue()){
this.setSame(true);
this.getPostalAddress().setAddressLine1(getResidentialAddress().getAddressLine1());
this.getPostalAddress().setAddressLine2(getResidentialAddress().getAddressLine2());
this.getPostalAddress().setAddressLine3(getResidentialAddress().getAddressLine3());
this.getPostalAddress().setCity(getResidentialAddress().getCity());
this.getPostalAddress().setState(getResidentialAddress().getState());
this.getPostalAddress().setPostCode(getResidentialAddress().getPostCode());
System.out.println("Value was true");
System.out.println("Postal Address " + getPostalAddress());
System.out.println("Residential Address " + getResidentialAddress());
}else{
setPostalAddress(new Address());
}
}

Prevent tab-siwtch on p:tabView when form validation fails

I'm using a tabView-Element of primefaces. The first tab points to the "Home" element the second one to a registration form. The registration form is validated. The problem is, when the form is validated the user is redirect to the home tab. When the user navigates back, he can see the validation errors.
This seems to be a more or less common problem, but I did not find a proper solution. I tried out Oleg Varaksin suggestion to prevent a user switching tabs when a form validation failed, but my problem starts earlier.
I tried to fiddle aorund with the onTabChange event but with no success. Is there a mistake in my code or how can I approach may probelm? I would welcome a push in the right direction.
<p:tabView id="mainTabView">
<p:tab title="Startseite" id="startPage">
<p:layout style="min-width:400px;min-height:400px;border:none !important"
id="layout_login">
<p:layoutUnit position="west" size="305">
<p:panel>
<h:form id="loginForm">
<p:panelGrid columns="2" styleClass="gridWithNoBorders reducedFontSize">
<p:outputLabel value="Benutzername:" />
<p:inputText size="14" value="#{data.username}" />
<p:outputLabel value="Passwort:" />
<p:inputText size="14" value="#{data.loginPassword}" />
</p:panelGrid>
<p:separator />
<h:commandButton styleClass="reducedFontSize" value="Anmelden" />
</h:form>
</p:panel>
</p:layoutUnit>
<p:layoutUnit position="center">
<p:panel>
Lorem ipsum dolor sit amet(...)
</p:panel>
</p:layoutUnit>
</p:layout>
</p:tab>
<p:tab id="registrationPage" title="#{ivy.cms.co('/Translations/Registration/tabTitleRegistration')}" >
<h:form id="registrationForm">
<p:panel header="#{ivy.cms.co('/Translations/Registration/panelHeaderRegistration')}">
<p:panelGrid columns="3">
<p:outputLabel value="#{ivy.cms.co('/Translations/Registration/labelEmail')}" />
<p:inputText value="#{data.email}" id="email1" required="true" requiredMessage="#{ivy.cms.co('/Translations/Registration/enterEmailAddress')}">
<f:validator validatorId="EmailValidator" />
<f:validator validatorId="EmailCompareValidator" />
</p:inputText>
<p:message for="email1" />
<p:outputLabel value="#{ivy.cms.co('/Translations/Registration/labelRepeatEmail')}" />
<p:inputText value="#{data.emailConfirm}" id="email2" required="true" requiredMessage="#{ivy.cms.co('/Translations/Registration/repeatMailAddress')}">
<f:validator validatorId="EmailValidator" />
</p:inputText>
<p:message for="email2"/>
<p:outputLabel value="#{ivy.cms.co('/Translations/Registration/labelPrename')}" />
<p:inputText value="#{data.prename}" id="prename" required="true" requiredMessage="#{ivy.cms.co('/Translations/Registration/enterPrename')}"/>
<p:message for="prename"/>
<p:outputLabel value="#{ivy.cms.co('/Translations/Registration/labelSurname')}" />
<p:inputText value="#{data.surname}" id="surname" required="true" requiredMessage="#{ivy.cms.co('/Translations/Registration/enterSurname')}"/>
<p:message for="surname"/>
<p:outputLabel value="#{ivy.cms.co('/Translations/Registration/labelPassword')}" />
<p:password id="pwd1" value="#{data.registrationPassword}" match="pwd2"
required="true" feedback="true" requiredMessage="#{ivy.cms.co('/Translations/Registration/enterPassword')}"
weakLabel="#{ivy.cms.co('/Translations/Registration/passwordWeak')}"
goodLabel="#{ivy.cms.co('/Translations/Registration/passwordMedium')}"
strongLabel="#{ivy.cms.co('/Translations/Registration/passwordStrong')}" />
<p:message for="pwd1"/>
<p:outputLabel value="#{ivy.cms.co('/Translations/Registration/labelRepeatPassword')}" />
<p:password id="pwd2" value="#{data.confirmPassword}" required="true" requiredMessage="#{ivy.cms.co('/Translations/Registration/repeatPassword')}"/>
<p:message for="pwd2"/>
<h:commandButton value="#{ivy.cms.co('/Translations/Registration/finishRegistration')}" actionListener="#{logic.startRegistration}" >
<p:ajax event="click" listener="#{logic.startRegistration}"/>
</h:commandButton>
</p:panelGrid>
</p:panel>
</h:form>
</p:tab>
</p:tabView>
I had to combine the binding and ajax to achieve my goal. It seems that the activeIndex is resetted after the form validation (?) therefore it is not honored after submitting the form. I've used the approach that was suggested by Steves to use the binding property. So here is the working code:
xhtml:
<p:layoutUnit position="center">
<p:tabView id="mainTabView" binding="#{tabIndexHelper.messagesTab}">
<p:ajax event="tabChange" listener="#{tabIndexHelper.onTabChange}" />
<p:tab title="Startseite" id="startPage">
<ui:include src="HomePage.xhtml" />
</p:tab>
<p:tab id="registrationPage" title="#{ivy.cms.co('/Translations/Registration/tabTitleRegistration')}" >
<ui:include src="RegisterPage.xhtml" />
</p:tab>
</p:tabView>
</p:layoutUnit>
And the backing bean:
private TabView messagesTab = new TabView();
public TabView getMessagesTab () {
return messagesTab;
}
public void setMessagesTab(TabView messagesTab ) {
this.messagesTab = messagesTab;
}
public void onTabChange(TabChangeEvent event) {
TabView tabView = (TabView) event.getComponent();
int activeIndex = tabView.getChildren().indexOf(event.getTab());
this.messagesTab.setActiveIndex(activeIndex);
}
Thanks for support. :)
You need to fix the current tab selected if you don't the update or validation should reset the tabview with default tab selected(the first one).
So you could use activeIndex attribut from tabView :
<p:tabView activeIndex="#{bean.activeIndex}"/>
From Primeface User Guide:
activeIndex is an Integer with default value 0. Index of the active tab.
And create an event for set this var like that :
<p:ajax event="tabChange" listener="#{bean.onTabChange}"/>

Orchard cms adding data-mediapicker-uploadpath to a custom type

I have created a custom type in orchard cms, that has a two column lay out
It has 2 header text fileds and 2 content HTML flavour fileds
Heres the migration :
public class MigrationTwoColumnPageType : DataMigrationImpl
{
public int Create()
{
// Define the project type
ContentDefinitionManager.AlterTypeDefinition("TwoColumnPage", cfg => cfg
.WithSetting("Stereotype", "Content")
.CommomPart()
.AutoroutePart()
.WithPart("TitlePart")
.WithPart("MenuPart")
.WithPart("TagsPart")
.WithPart("PublishLaterPart")
.WithPart("TwoColumnPage")
.Creatable()
.Draftable());
return 1;
}
public int UpdateFrom1()
{
// Define project part - having a part with the same name will create fields in the project type
ContentDefinitionManager.AlterPartDefinition("TwoColumnPage", builder => builder
.TextField("Column1Title", Flavour.Large)
.TextField("Column1Text", Flavour.Html)
.TextField("Column2Title", Flavour.Large)
.TextField("Column2Text", Flavour.Html)
.Attachable());
return 2;
}
}
NOTE: TextField is a custom extension method to make things less verbose
When I try and use the media picker to up load an image into one of these content fields I get a folder not found error, - I have traced this back to the media path on the Request querystring not being set
// media directory to save uploaded files into
var mediaPath = Request["uploadpath"];
in ../../Orchard.MediaPicker/Views/admin/Tab_Url.cshtml
Is there some way to set this using filed settings ?
Seems to work fine for any pages I create, but custom types .... how do I set this value ?
UPDATE
Heres the xml meta data for a page...
<!--Exported from Orchard-->
<Orchard>
<Recipe>
<Name>Generated by Orchard.ImportExport</Name>
<Author>admin</Author>
</Recipe>
<Metadata>
<Types>
<Page ContentTypeSettings.Creatable="True" ContentTypeSettings.Draftable="True" TypeIndexing.Included="true" DisplayName="Page">
<NavigationPart />
<CommonPart DateEditorSettings.ShowDateEditor="true" />
<PublishLaterPart />
<TitlePart />
<AutoroutePart AutorouteSettings.AllowCustomPattern="true" AutorouteSettings.AutomaticAdjustmentOnEdit="false" AutorouteSettings.PatternDefinitions="[{Name:'Title', Pattern: '{Content.Slug}', Description: 'my-page'}]" AutorouteSettings.DefaultPatternIndex="0" />
<BodyPart />
<TagsPart />
<LocalizationPart />
</Page>
</Types>
<Parts>
<NavigationPart ContentPartSettings.Attachable="True" />
<CommonPart ContentPartSettings.Attachable="True" />
<PublishLaterPart ContentPartSettings.Attachable="True" />
<TitlePart ContentPartSettings.Attachable="True" />
<AutoroutePart ContentPartSettings.Attachable="True" />
<BodyPart ContentPartSettings.Attachable="True" BodyPartSettings.FlavorDefault="html" />
<TagsPart ContentPartSettings.Attachable="True" />
<LocalizationPart />
</Parts>
</Metadata>
</Orchard>
Here's the XML meta for my custom type, using TestFiledSetting instead of BodyPartSetting
<!--Exported from Orchard-->
<Orchard>
<Recipe>
<Name>Generated by Orchard.ImportExport</Name>
<Author>admin</Author>
</Recipe>
<Metadata>
<Types>
<TwoColumnPage Stereotype="Content" OwnerEditorSettings.ShowOwnerEditor="false" ContentTypeSettings.Creatable="True" ContentTypeSettings.Draftable="True" DisplayName="Two Column Page">
<CommonPart />
<AutoroutePart AutorouteSettings.PatternDefinitions="[{Name:'/Title', Pattern: '/{Content.Slug}', Description: 'my-page'}]" />
<TitlePart />
<MenuPart />
<TagsPart />
<PublishLaterPart />
<TwoColumnPage />
</TwoColumnPage>
</Types>
<Parts>
<CommonPart ContentPartSettings.Attachable="True" />
<AutoroutePart ContentPartSettings.Attachable="True" />
<TitlePart ContentPartSettings.Attachable="True" />
<MenuPart ContentPartSettings.Attachable="True" />
<TagsPart ContentPartSettings.Attachable="True" />
<PublishLaterPart ContentPartSettings.Attachable="True" />
<TwoColumnPage ContentPartSettings.Attachable="True">
<Column1Title.TextField TextFieldSettings.Required="True" TextFieldSettings.Flavor="Large" TextFieldSettings.Hint="" />
<Column1Text.TextField TextFieldSettings.Required="True" TextFieldSettings.Flavor="Html" TextFieldSettings.Hint="" />
<Column2Title.TextField TextFieldSettings.Required="True" TextFieldSettings.Flavor="Large" TextFieldSettings.Hint="" />
<Column2Text.TextField TextFieldSettings.Required="True" TextFieldSettings.Flavor="Html" TextFieldSettings.Hint="" />
</TwoColumnPage>
</Parts>
</Metadata>
</Orchard>
No mention of data-mediapicker-uploadpath in either. I'm still lost!