I am trying to build an JSF library control for XPages based on the examples by Keith Strickland.
http://xprentice.gbs.com/A55BAC/keithstric.nsf/default.xsp?documentId=82770C11FA7B9B21852579C100581766
I am trying to create a function which creates an InputBox control with an attached DatePicker control.
here is code that I have tried :
XspInputText inputText = new XspInputText();
inputText.setId("inputText1");
DateTimeConverter converter = new DateTimeConverter();
converter.setType("date");
inputText.setConverter(converter);
XspDateTimeHelper dateTimeHelper = new XspDateTimeHelper();
dateTimeHelper.setId("dateTimeHelper1");
inputText.getChildren().add(dateTimeHelper);
inputText.setRendered(true);
this.getChildren().add(inputText);
The InputText control is rendered but the Converter, Validator and DatePicker button are not rendered.
Hi the answer from Keith solved the problem but now I had an other. I have tryed to add the inputtext to an fromtable from the exlib. Without the formtable arround the "DateTimePicker" is rendered correctly, but with the Formtable it is only rendered as a textfield.
here is the complete code:
public class Libcontrol extends UIComponentBase implements FacesComponent {
private static final String RENDERER_TYPE = "de.chris.Libcontrol ";
private static final String COMPONENT_FAMILY = "de.chris";
public void CommonContactInfo() {
setRendererType(RENDERER_TYPE);
}
#Override
public String getFamily() {
return COMPONENT_FAMILY;
}
#SuppressWarnings("unchecked")
public void initBeforeContents(FacesContext arg0) throws FacesException {
UIFormTable table = new UIFormTable();
table.setId("mytable");
table.setDisableRowError(false);
table.setDisableErrorSummary(true);
table.setLabelPosition("left");
UIFormLayoutRow row = new UIFormLayoutRow();
row.setId("myrow");
row.setLabel("DATEROW");
XspInputText inputText = new XspInputText();
inputText.setId("inputText1");
DateTimeConverter converter = new DateTimeConverter();
converter.setType("date");
inputText.setConverter(converter);
XspDateTimeHelper dateTimeHelper = new XspDateTimeHelper();
dateTimeHelper.setId("dateTimeHelper1");
inputText.getChildren().add(dateTimeHelper);
inputText.setRendered(true);
this.getChildren().add(inputText);
row.getChildren().add(inputText);
table.getChildren().add(row);
this.getChildren().add(table);
}
public void buildContents(FacesContext arg0, FacesComponentBuilder arg1) throws FacesException {
// Do Nothing
}
/**
* This method must be present because we're implementing FacesComponent
*/
public void initAfterContents(FacesContext arg0) throws FacesException {
// Do nothing
}
}
I'm not sure where the problem is, any ideas?
OK, think I may have found your issue. On the XPage/Custom Control itself, set the properties for:
dojoParseOnLoad=true
dojoTheme=true
or, if you don't want to set those properties in your XPage/Custom Control you can do it in the renderer encodeBegin with the following lines somewhere before the call to super.encodeBegin():
//Here context = FacesContext or FacesContext.getCurrentInstance();
UIViewRootEx rootEx = (UIViewRootEx) context.getViewRoot();
rootEx.setDojoParseOnLoad(true);
rootEx.setDojoTheme(true);
Related
Hi I’m trying to create a horizontal slide where each horizontal page will have a button that will call a Dialog but onClick is not working in extends Pageradapter can anyone tell me what I’m doing wrong?
I gave the name onClickApprove to onClick that I want you to call Dialog. This Dialog is calling an Activity with a Ratingbar to make an assessment.
Thank you.
public class SliderAdapterUsado extends PagerAdapter {
Context context;
LayoutInflater layoutInflater;
BottomSheetDialog dialog;
Button show;
public SliderAdapterUsado(Context context){
this.context = context;
}
public String[] slide_rota ={
"Titulo1",
"Titulo2"
};
public String[] slide_nome={
"Descrção do titulo 1",
"Descrção do titulo 2"
};
#Override
public int getCount(){
return slide_rota.length;
}
#Override
public boolean isViewFromObject(View view, Object object){
return view == (LinearLayout) object;
}
#Override
public Object instantiateItem(ViewGroup container, int position){
layoutInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.slide_layout_usados, container, false);
TextView slideHeading = view.findViewById(R.id.slide_rota);
TextView slideDescricao = view.findViewById(R.id.slide_nome);
slideHeading.setText(slide_rota[position]);
slideDescricao.setText(slide_nome[position]);
container.addView(view);
return view;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object){
container.removeView((LinearLayout)object);
}
public void onClickAvaliar(View view) {
show = view.findViewById(R.id.show);
dialog = new BottomSheetDialog(dialog.getContext());
show.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
createDialog();
dialog.show();
}
});
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
}
private void createDialog(){
View view = layoutInflater.inflate(R.layout.activity_rating, null, false);
Button FeedBack = view.findViewById(R.id.FeedBack);
FeedBack.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dialog.dismiss();
}
});
dialog.setContentView(view);
}
}
Please read the documentation.
Note this in particular (emphasis mine):
To define the click event handler for a button, add the android:onClick attribute to the element in your XML layout. The value for this attribute must be the name of the method you want to call in response to a click event. The Activity hosting the layout must then implement the corresponding method.
The expectation is that the value set on the onClick xml attribute will be a method on the hosting Activity. Yours is in the adapter. That's why it doesn't work.
So either move that method to the hosting activity, or just handle the click event explicitly:
...
TextView slideHeading = view.findViewById(R.id.slide_rota);
TextView slideDescricao = view.findViewById(R.id.slide_nome);
Button slideButton = view.findViewById(R.id.slide_button);
slideButton.setOnClickListener (...)
...
This is how I'm rendering my composite component inside a loop, it works, but when I switch to edit mode and sumbmit new values I can't retrieve them from the InputText.
#FacesComponent("customComponent")
public class CustomComponent extends UIInput implements NamingContainer, Serializable {
private static final long serialVersionUID = 1L;
#Override
public String getFamily() {
return UINamingContainer.COMPONENT_FAMILY;
}
private UIComponent component;
private HtmlInputText inputTextValue;
#Override
public void encodeBegin(FacesContext context) throws IOException {
AttributeObject attrObject = (AttributeObject) getAttributes().get("value");
Boolean enableInput = (Boolean) getAttributes().get("enableInput");
if (attrObject.getAttributeValue() != null) {
if (attrObject.getAttributeDescriptor().getDataType() == DataTypeConstants.TEXT && enableInput) {
InputText inputText = new InputText();
inputText.setRequired(true);
inputText.setValueExpression("binding",
createValueExpression("#{searchController.myComponent}", UIComponent.class));
inputText.setId("editableTextId");
inputText.encodeAll(context);
inputText.setParent(this);
component = inputText;
} else if (attrObject.getAttributeDescriptor().getDataType() == DataTypeConstants.TEXT
&& enableInput == false) {
OutputLabel outputLabel = new OutputLabel();
outputLabel.setValue(attrObject.getAttributeValue());
outputLabel.encodeAll(context);
outputLabel.setId("nonEditatbleId");
component = outputLabel;
}
}
}
private ValueExpression createValueExpression(String valueExpression, Class<?> valueType) {
FacesContext facesContext = FacesContext.getCurrentInstance();
return facesContext.getApplication().getExpressionFactory()
.createValueExpression(facesContext.getELContext(), valueExpression, valueType);
}
Ok I think I found what caused all that mad performance problems. I did some logic inside a getter and because that getter was getting called multiple times that caused performance issues.
I have a javafx design in the file javafx.fxml where the root element has the following attribute
fx:controller="de.roth.jsona.javafx.ViewManagerFX"
This controller class has a singleton machanism and is binded with some ui-elements.
public class ViewManagerFX {
private static ViewManagerFX instance = new ViewManagerFX();
#FXML
private Slider volumeSlider;
#FXML
private Label volumeLabel;
public IntegerProperty volumeValue = new SimpleIntegerProperty();
#FXML
private TabPane musicTabs;
public List<StringProperty> tabNames = new ArrayList<StringProperty>();
public static ViewManagerFX getInstance() {
return (instance);
}
public void initialize() {
// Volume
volumeSlider.valueProperty().bindBidirectional(volumeValue);
volumeLabel.textProperty().bindBidirectional(volumeValue, new Format() {
#Override
public StringBuffer format(Object obj, StringBuffer toAppendTo,
FieldPosition pos) {
toAppendTo.append(obj);
toAppendTo.append("%");
return toAppendTo;
}
#Override
public Object parseObject(String source, ParsePosition pos) {
return null; // no need to be implemented
}
});
volumeValue.set(Config.getInstance().VOLUME);
}
public void addMusicFolderTab(final String t, final ArrayList<MusicListItem> items) {
Platform.runLater(new Runnable() {
#Override
public void run() {
Tab m = new Tab("Test Tab");
musicTabs.getTabs().add(0, m);
}
});
}
}
The method addMusicFolderTab is called from a thread that is used to scan files and directories.
In the initialize method I can access the ui-elements but in the method addMusicFolderTab, that is called from the filescanner-thread, the variable musicTabs is null. Here is the exception:
java.lang.NullPointerException
at de.roth.jsona.javafx.ViewManagerFX$3.run(ViewManagerFX.java:110)
I have no clue, why I can't access the TabPane from outside the initialize method.
Aside from the many questionable patterns used here, the problem is that your ViewManagerFX singleton (besides not being a singleton) never has its instance set.
When using FXML, the Controller is created and loaded dynamically by Reflection from the FXMLoader.
What happens is that by calling ViewManagerFX.getInstance(), you access the a different controller than the one created by the FXMLoader. The instance you access is the one created here:
private static ViewManagerFX instance = new ViewManagerFX();
The quickest way to solve the issue is to set the instance in the initialize() since it's called by the FXMLoader on the instance created by the FXMLoader.
public void initialize() {
instance = this;
// Volume
...
}
I'm trying to implement a Custom Naviguation, that do the usual job and update my breadcrumb.
public class CustomNaviguationHandler extends NavigationHandlerImpl{
public void handleNavigation(FacesContext context, String fromAction, String outcome) {
//do the breadcrumb update
super.handleNavigation(context, fromAction, outcome);
}
}
But when I debug it, the method is executed 2 times once,
The 1st time, fromAction and outcome are null
The 2nd time, these parameters contains the right values.
The handler has been registered in the faces-config.xml
<navigation-handler>my.package.CustomNaviguationHandler</navigation-handler>
I'm not sure to understant why? Any Idea?
You should not extend the JSF impl class NavigationHandlerImpl at all. You should instead extend the JSF API class NavigationHandler.
Here's a kickoff example. Do your job in the handleNavigation() method. If you don't want to take responsibility on navigation, delegate to the parent.
public class CustomNavigationHandler extends NavigationHandler {
private NavigationHandler parent;
public CustomNavigationHandler(NavigationHandler parent) {
this.parent = parent;
}
#Override
public void handleNavigation(FacesContext context, String from, String outcome) {
parent.handleNavigation(context, from, outcome);
}
}
I have tryed to build a Java Class in JSf witch adds a view with a Pager to an XPage
Im Using a UiDataview in this simple example but my problem is that the Pager witch is added to the result is never displayed in my Xpage. anyone an idea what i have to do?
public class MainLibcontrol extends UIComponentBase implements FacesComponent {
private static final String RENDERER_TYPE = "de.my.MainLibcontrol";
private static final String COMPONENT_FAMILY = "de.my";
public MainLibcontrol() {
setRendererType(RENDERER_TYPE);
}
#Override
public String getFamily() {
return COMPONENT_FAMILY;
}
#SuppressWarnings("unchecked")
public void initBeforeContents(FacesContext arg0) throws FacesException {
try {
UIDataView viewtable = new UIDataView();
viewtable.setColumnTitles(true);
CategoryColumn categoryColumn = new CategoryColumn();
categoryColumn.setComponent(viewtable);
categoryColumn.setColumnName("form");
categoryColumn.setColumnTitle("form");
categoryColumn.setContentType("text");
viewtable.addCategoryColumn(categoryColumn);
DominoViewData data = new DominoViewData();
data.setComponent(viewtable);
data.setViewName("142342");
data.setVar("view2");
viewtable.setData(data);
viewtable.setId("dataView1");
viewtable.setRows(3);
SummaryColumn summaryColumn = new SummaryColumn();
summaryColumn.setComponent(viewtable);
summaryColumn.setColumnName("5");
summaryColumn.setColumnTitle("5");
viewtable.setSummaryColumn(summaryColumn);
XspPager pager = new XspPager();
pager.setPartialRefresh(true);
pager.setLayout("Previous Group Next");
pager.setId("pager1");
viewtable.getChildren().add(pager);
this.getChildren().add(viewtable);
} catch (Exception e) {
e.printStackTrace();
}
}
public void buildContents(FacesContext arg0, FacesComponentBuilder arg1) throws FacesException {
.....
}
public void initAfterContents(FacesContext arg0) throws FacesException {
....
}
}
I haven't tried this out, but I would imagine you want to add it as a facet of the viewTable not as a child.
so your line should be
viewtable.getFacets().put("headerPager", pager);