I tried to set up a simple JSF 2.2 application using MyFaces 2.2.8.
Since MyFaces has some context parameters that I never used before, I tried to get familiar with those.
So I got to use org.apache.myfaces.JSF_JS_MODE for the first time and ran into problems with h:commandLink.
The commandLink is trying to call myfaces.oam.submitForm() which is not defined if I set the mode to minimal-modern.
If I set the mode to minimal or normal it works.
From reading some internet articles I assume this is a bug because submitForm is neither part of jsf-legacy.js nor jsf-i18n.js nor jsf-experimental.js and it apparently is needed by h:commandLink.
Also the source code comment of org.apache.myfaces.shared.renderkit.html.util.ResourceUtils.markScriptAsRendered(FacesContext, String, String) tells me
oamSubmit script is included inside jsf.js
here:
public static void markScriptAsRendered(FacesContext facesContext, String libraryName, String resourceName)
{
getRenderedScriptResources(facesContext).put(
libraryName != null ? libraryName+'/'+resourceName : resourceName, Boolean.TRUE);
if (JAVAX_FACES_LIBRARY_NAME.equals(libraryName) &&
JSF_JS_RESOURCE_NAME.equals(resourceName))
{
// If we are calling this method, it is expected myfaces core is being used as runtime and note
// oamSubmit script is included inside jsf.js, so mark this one too.
getRenderedScriptResources(facesContext).put(
MYFACES_LIBRARY_NAME+'/'+MYFACES_JS_RESOURCE_NAME, Boolean.TRUE);
}
}
What am I missing here? Thanks in advance!
I can confirm it is a bug. Solved in MYFACES-4034 for 2.2.10
Related
I have a parent component and a child component with an event callback where I want it to pass back a type of T.
The issue I'm having is that I have an error about converting
MethodGroup to EventCallback.
If I convert this to using an Action then it works, but I can't do it async which isn't ideal.
Any ideas what I'm doing wrong?
Parent
<Child DeleteCallback="#OnDelete"></Child>
public async Task OnDelete(T item)
{ ... }
Child
#typeparam T
[Parameter]
public EventCallback<T> DeleteCallback { get; set; }
<a #onclick="() => DeleteCallback.InvokeAsync(item)"></a>
I've added a repo here explaining the problem. Looking at the Issues for Blazor, this should;ve been fixed in 2019. https://github.com/scott-david-walker/EventCallbackError
You were close:
<ChildComponent Item="someModel" T="SomeModel" DeleteCallback="OnDeleteSomeModel" />
#code {
SomeModel someModel = new SomeModel();
void OnDeleteSomeModel(SomeModel someModel)
{
...
}
}
The EventCallback uses a generic type and blazor cannot infer it if you don't pass the type to the component.
This means that if you have a EventCallback<T> you need to pass the value of T to the component e.g. T="SomeType".
In my case I declared a nullable EventCallback? - you can't do that.
I've experienced that the syntax was spot on and still getting this error.
Restarting Visual Studio 2019 solved the problem for me. Cleaning and rebuilding was not enough.
For some reason Visual Studio kept a previous signature I had used. Cleaning, restarting, emptying bin/obj folders etc did not work. I had to rename the method, which worked for me.
The following syntax worked for me:
// in the component (C#):
[Parameter]
public EventCallback<MovingEventArgs> OnMoving { get; set; }
// on the using side (Razor):
OnMoving="(Component.MovingEventArgs o) => OnMoving(o)"
// on the using side (C#):
protected void OnMoving( Component.MovingEventArgs e ) {
}
There seems to have been a change and the documentation is not up to date.
This event is also using custom event arguments.
For anyone fighting this with the MudBlazor MudTable I found this worked use #bind-SelectedItem and don't pass any parameters to the commit function.
<MudTable T="POCO" Items="#MyState.POCOs"
#bind-SelectedItem="_selectedPOCO"
OnCommitEditClick="#(() => commitPOCO())"
CommitEditTooltip="Save Changes?">
#code {
private POCO _selectedPOCO;
private async void commitPOCO()
{
// all the changed values are in _selectedPOCO
...
}
In my case, the problem solved when I defined the #typeparam manually(not by inference)(TItem="int").
<MyComponent TItem="int" OnChange="Component_Changed" />
Okay I just spent hours trying to figure this out. Turns out on my end the problem was I have sync fusion in the project and I had explicitly define the name space of the Event call back arguments which in my case were Microsoft.AspNetCore.Components.ChangeEventArgs in the child component and then creating an async method to pass back data to the parent.
In my case it was a phantom error among tens others that never went away no matter what I do. Meaning I could still build and run a solution without problems, despite so many erorrs.
What helped me was this solution: https://stackoverflow.com/a/66219566/1215913
However, I finally found a solution after a few hours of digging. To
get rid of the phantom errors I closed Visual Studio, deleted the
files in the following folder, and then re-opened the solution:
C:\Users<Username>\AppData\Local\Temp\VSFeedbackIntelliCodeLogs\Suggestions\
The only difference is I removed all of the folders that start with VS (C:\Users\<Username>\AppData\Local\Temp\VS*) since there was no this exact path as #rovert mentions in his post.
This seems to be some common problem with Blazor and IntelliSense. I also often see that auto-formatter fails to correctly format the razor code (text indentations are a mess).
In my case I got the error
Error (active) CS1503 Argument 2: cannot convert from 'method group'
to 'EventCallback'
for ValueChanged with the following code:
<MatAutocompleteList TItem="UseCase" Items="#selectUseCases" ValueChanged=#SelectUseCases>
<ItemTemplate>
#context?.Label
</ItemTemplate>
</MatAutocompleteList>
#code
{
private UseCase SelectUseCases(UseCase useCaseDto)
{
if (useCaseDto != null)
{
//Do stuff
}
return null;
}
}
Changed to private void SelectUseCases(UseCase useCaseDto), removed all returns and the error disappeared.
After trying all other solutions proposed here, including:
Making sure I was providing T=myType
Clean and rebuild
Restart Visual Studio
Rename the method by appending a letter to its name and aligning its binding
The only thing that worked for me was literally deleting the line with the binding, saving, recompiling, then writing it back.
In doing so, I in fact realized that I was typing:
SelectedItemChanged="#SelectedItemsChanged"
instead of:
SelectedItemsChanged="#SelectedItemsChanged"
I was missing an s in the binding. The method itself had a signature receiving a HashSet of my type, so it could only deal with Items, not a single item.
I just tried to add a composite JSF component into my weld project on glassfish 3.1.2.
This always fails with a null pointer exception.
I traced down the problem and found out, that it results from the following code within the class
com.sun.faces.application.ApplicationImpl.
#Override
public UIComponent [More ...] createComponent(FacesContext context, Resource componentResource) throws FacesException {
// RELEASE_PENDING (rlubke,driscoll) this method needs review.
Util.notNull("context", context);
Util.notNull("componentResource", componentResource);
UIComponent result = null;
// use the application defined in the FacesContext as we may be calling
// overriden methods
Application app = context.getApplication();
ViewDeclarationLanguage pdl = app.getViewHandler().getViewDeclarationLanguage(context, context.getViewRoot().getViewId());
BeanInfo componentMetadata = pdl.getComponentMetadata(context, componentResource);
....
The problem seems to be, that the ViewDeclarationLanguage pdl result to null and therefore the call for getComponentMetadata(...) result in the NPE.
The question is, why is this ViewDeclarationLanguage null? Is there anything special in this stack or do I have to configure any further properties?
Thank you very much for your help!
Thomas
I found the solution myself, but would like to share it, if someone else stumbles over the same problem.
Within the faces-config, there was a definition of a custom view-handler. This view-handler did not handle this request correctly, so I changed it to the "org.jboss.weld.jsf.ConversationAwareViewHandler".
Now it works!
In Struts1, I heard that there is a classloader vulnerability issue which is cause by CVE-2014-0114. But I am unable to reproduce this respect to my project. Can anyone help me how to reproduce this issue. I googled but not get any procedure of reproducing.
I am using struts-1.1, Jboss -4.2.3.GA, Apache 2.2.0, MySql 5.0.37, JKMod, JDK 1.6.0_12, Ant 1.7.0 for my web project.
Try to invoke a URL which is mapped to a struts action (backed by an action form). The framework will try to populate your form bean from query parameters. So if you have a query parameter like ?class.classLoader.defaultAssertionStatus=true, it translates to formBean.getClass().getClassLoader().setDefaultAssertionStatus(true).
If you have enabled debug logging, you would see the following messages:
2014-05-05 12:57:50,238 DEBUG [org.apache.struts.action.RequestProcessor] Populating bean properties from this request
2014-05-05 12:57:50,238 DEBUG [org.apache.commons.beanutils.BeanUtils] BeanUtils.populate(com.xxx.struts.demo.web.form.SimpleForm#71909bc, {class.classLoader.defaultAssertionStatus=[Ljava.lang.String;#a6b23fd4})
2014-05-05 12:57:50,238 DEBUG [org.apache.commons.beanutils.BeanUtils] setProperty(com.xxx.struts.demo.web.form.SimpleForm#71909bc, class.classLoader.defaultAssertionStatus, [true])
2014-05-05 12:57:50,246 DEBUG [org.apache.commons.beanutils.BeanUtils] Target bean = com.ibm.ws.classloading.internal.AppClassLoader#3ac10955
2014-05-05 12:57:50,246 DEBUG [org.apache.commons.beanutils.BeanUtils] Target name = defaultAssertionStatus
2014-05-05 12:57:50,250 DEBUG [org.apache.commons.beanutils.ConvertUtils] Convert string 'true' to class 'boolean'
2014-05-05 12:57:50,250 DEBUG [org.apache.commons.beanutils.ConvertUtils] Using converter org.apache.commons.beanutils.converters.BooleanConverter#de2943ef
2014-05-05 12:57:50,250 DEBUG [org.apache.commons.beanutils.PropertyUtils] setSimpleProperty: Invoking method public void java.lang.ClassLoader.setDefaultAssertionStatus(boolean) with value true (class java.lang.Boolean)
I have tried in more than 2 ways to reproducing purpose. It works fine.
http://127.0.0.1:8080/MyFormGroupEditSection.do?com.macao.DelphyHacker.Marathonclass.marathonId=34&groupId=862
http://127.0.0.1:8080/MyFormGroupEditSection.do?class.classLoader=true&groupId=862
For solution purpose of this problem, I want to add some comments. You can follow this 2 links. Hopefully, it will help you to eradicate this problem.
http://h30499.www3.hp.com/t5/HP-Security-Research-Blog/Protect-your-Struts1-applications/ba-p/6463188#.U2J7xeaSxro
http://mail-archives.apache.org/mod_mbox/struts-announcements/201405.mbox/%3C53629980.8060805%40apache.org%3E
A Metasploit-based exploit is available on GitHub: https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/multi/http/struts_code_exec_classloader.rb and also at http://downloads.securityfocus.com/vulnerabilities/exploits/65999.rb.
See http://www.rapid7.com/db/modules/exploit/multi/http/struts_code_exec_classloader for reference.
Further to the solutions above I wanted to point out that adding a breakpoint in the ClassLoader at the line defaultAssertionStatus = enabled; within setDefaultAssertionStatus and a watcher at the line private boolean defaultAssertionStatus = false; is a great way of verifying if the above url modification: ?class.classLoader.defaultAssertionStatu‌​s=true has worked your defaultAssertionStatus should now be true.
Hope this helps!
Something like this works to test (in code at least)
try {
PropertyUtils.getNestedProperty(this, "class");
Logger.error(this, "SECURITY ISSUE- `class` attribute NOT DISABLED for BeanUtil introspection, See: CVE-2014-0114 ");
} catch (java.lang.NoSuchMethodException nse) {
Logger.info(this, "`class` is disabled as a property for introspection in struts for security");
} catch (Exception e) {
Logger.warn(this, e.getMessage(), e);
}
I'm creating an application that uses JavaFX 2.2 and have run into a problem. I'm trying to use a LineChartBuilder, like so:
LineChart<Number, Number> chart = LineChartBuilder.<Number, Number>
create()
.XAxis(NumberAxisBuilder.create().label("X axis").build())
.YAxis(NumberAxisBuilder.create().label("Y axis").build())
.build();
However, I'm getting the following compiler errors:
java: reference to create is ambiguous, both method create() in
javafx.scene.layout.RegionBuilder and method <X,Y>create() in
javafx.scene.chart.LineChartBuilder match
and
java: cannot find symbol
symbol: method XAxis(javafx.scene.chart.NumberAxis)
location: class javafx.scene.layout.RegionBuilder<capture#1 of ?>
I know the first error means LineChartBuilder descends from RegionBuilder and both define a create() method, and the second means it's assuming the method comes from RegionBuilder and therefore cannot find the XAxis method. I've even tried casting it,
LineChart<Number, Number> chart =
((LineChartBuilder<Number, Number, ?>)
LineChartBuilder.<Number, Number>create())....
But I get the same compiler errors.
My question is, is this a mistake in LineChartBuilder or am I using it wrong? Maybe there's even a workaround?
Are you sure you are running with JavaFX 2.2 and not a JDK8 pre-release?
JDK8 will experience these issues with builders coded for JavaFX 2.2: see RT-24272.
Workaround is to use new LineChart(xaxis, yaxis). See also the Oracle forum thread post on this issue.
I've been stuck on this issue for a while now. I found a earlier post where BalusC gave advice on creating your own converter called "EmptyToNullConverter" for JSF version 1.2
or specifying a context parameter in JSF 2.0
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
None of these options has worked for me. Has it worked for other people.
Doing some investigation of my own I ended up stepping through the UIInput source. I can see the value is null until it is passed to the ValueExpression. Unfortunately I do not have the source for that so I could not drill down further. I'm assuming it is here where it ends up instantiating a new String Type and rather passing that to the model property?
My environment is as follows
running Mojarra RI using the jsf-api-2.0.3 and jsf-impl-2.0.3 jars
also using richfaces 3.3.3, so I had to disable the viewhandler for jsf2. Still using facelets jar as a result
All this is running on Tomcat 6
Any help will be appreciated
I know we had this problem using Richfaces and Sun's default JSF implementation 1.2.
One way to work around the problem is using your own custom converters for whatever type you need that convert empty values (0, "") to nulls.
Other way is doing the conversion inside your backingbean:
MyBackingBean {
String myValue;
public void setMyValue(String v) {
if (v==null || v.trim().length==0) {
myValue==null;
} else {
myValue=v;
}
}
public String getMyValue() {
return myValue;
}
}